//
//  PhotoTranstion.m
//  Shengzhuli
//
//  Created by 卡忙科技 on 16/8/27.
//  Copyright © 2016年 kamangkeji. All rights reserved.
//

#import "PhotoTranstion.h"

@interface PhotoTranstion()

@property (nonatomic,assign) TranstionType type;

@end

@implementation PhotoTranstion

- (instancetype)initWithTranstionType:(TranstionType)type
{
    if (self = [super init]) {
        self.type = type;
    }
    return self;
}

- (NSTimeInterval)transitionDuration:(nullable id <UIViewControllerContextTransitioning>)transitionContext
{
    return 1;
}
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext
{
    UIView *containerView = [transitionContext containerView];
    UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    [containerView addSubview:toVC.view];
    
    if (self.type == TranstionTypePresent) {
        toVC.view.alpha = 0;
        [UIView animateWithDuration:0.5 animations:^{
            toVC.view.alpha = 1;
        } completion:^(BOOL finished) {
            [transitionContext completeTransition:YES];
        }];
    } else {
        [UIView animateWithDuration:0.5 animations:^{
            fromVC.view.alpha = 0;
        } completion:^(BOOL finished) {
            [transitionContext completeTransition:YES];
        }];
    }
}


@end
